#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/delay.h>
#include <linux/ide.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/errno.h>
#include <linux/gpio.h>
#include <linux/cdev.h>
 #include <linux/device.h>
 #include <linux/of_gpio.h>
 #include <linux/semaphore.h>
 #include <linux/timer.h>
 #include <linux/irq.h>
 #include <linux/wait.h>
 #include <linux/poll.h>
 #include <linux/fs.h>
 #include <linux/fcntl.h>
 #include <linux/platform_device.h>
 #include <linux/fcntl.h>
 #include <asm/uaccess.h>
 #include <asm/io.h>

 #define PMU_GRF_BASE (0xFD5F8000)
 #define BUS_IOC_BASE (0xFD5F8000)
 #define BUS_IOC_GPIO1A_IOMUX_SEL_L (BUS_IOC_BASE + 0x0020)
 #define VCCIO1_4_BASE (0xFD5F9000)
 #define VCCIO1_4_IOC_GPIO1A_DS_L (VCCIO1_4_BASE + 0x0020)

 #define GPIO1_BASE (0xFEC20000)
 #define GPIO_SWPORT_DR_L (GPIO1_BASE + 0X0000)
 #define GPIO_SWPORT_DDR_L (GPIO1_BASE + 0X0008)
 #define REGISTER_LENGTH 4  // 寄存器长度


static void led_release(struct device *dev)
{
    printk(KERN_INFO "led_release\r\n");
}

// 设备结构体
static struct resource led_resources[] = {
    [0] = {
        .start = BUS_IOC_GPIO1A_IOMUX_SEL_L,
        .end = (BUS_IOC_GPIO1A_IOMUX_SEL_L + REGISTER_LENGTH - 1),
        .flags = IORESOURCE_MEM,
    },
    [1] = {
        .start = VCCIO1_4_IOC_GPIO1A_DS_L,
        .end = (VCCIO1_4_IOC_GPIO1A_DS_L + REGISTER_LENGTH - 1),
        .flags = IORESOURCE_MEM,
    },
    [2] = {
        .start = GPIO_SWPORT_DR_L,
        .end = (GPIO_SWPORT_DR_L + REGISTER_LENGTH - 1),
        .flags = IORESOURCE_MEM,
    },
    [3] = {
        .start = GPIO_SWPORT_DDR_L,
        .end = (GPIO_SWPORT_DDR_L + REGISTER_LENGTH - 1),
        .flags = IORESOURCE_MEM,
    }
};

static struct platform_device led_device = {
    .name = "jack-led",
    .id = -1,
    .dev = {
        .release = led_release,
    },
    .num_resources = ARRAY_SIZE(led_resources),
    .resource = led_resources,
};

static int __init ledDevive_init(void)
{ 
    return platform_device_register(&led_device);
}

static void __exit ledDevive_exit(void)
{
    platform_device_unregister(&led_device);
}

module_init(ledDevive_init);
module_exit(ledDevive_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("jack");
MODULE_INFO(intree, "Y");


